﻿




using System.Web.Mvc;
using Hotpot.Modules.Blogs.Services;

namespace Hotpot.Modules.Blogs.ModelBinders
{
    public class PostModelBinder : IModelBinder
    {
        private readonly IPostService postService;

        public PostModelBinder(IPostService postService)
        {
            this.postService = postService;
        }

        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            string blogName = (string)bindingContext.ValueProvider["blogName"].RawValue;
            string postSlug = (string)bindingContext.ValueProvider["postSlug"].RawValue;

            return postService.GetPost(blogName, postSlug);
        }
    }
}
